//
//  FPDesignCenterHomeCell.m
//  ForestPack
//
//  Created by jimmy on 2018/7/5.
//  Copyright © 2018年 郑洲. All rights reserved.
//

#import "FPDesignCenterHomeCell.h"
#import <Masonry.h>
#import "NewPagedFlowView.h"
#import "UIView+Utils.h"
#import "FPCustomButton.h"
#import "CHCardView.h"
#import "CHCardItemCustomView.h"

#pragma mark - DesignCenterBtnTableViewCell
@interface FPDesignCenterHomeCell()

@property (nonatomic, assign) CGFloat       cellHeight;
@property (nonatomic, strong) NSIndexPath * indexPath;

@property (nonatomic,strong)  UILabel     * topleftLab;
@property (nonatomic,strong)  UILabel     * topRightLab;
@property (nonatomic,strong)  UILabel     * botLeftLab;
@property (nonatomic,strong)  UILabel     * botRightLab;

@end

#pragma mark - 第一区的cell样式
@implementation FPDesignCenterHomeCell

+ (FPDesignCenterHomeCell *)cellWithTableView:(UITableView *)tableView andIndexPath:(NSIndexPath *)indexPath andCellHeight:(CGFloat)height
{
    static NSString *cellID = @"FPDesignCenterHomeCell";
    FPDesignCenterHomeCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[FPDesignCenterHomeCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.indexPath = indexPath;
        cell.cellHeight = height;
        [cell setViewUI];
    }
    
    return cell;
}

-(void)setCustomDemandListModel:(CustomDemandListModel *)customDemandListModel
{
    _customDemandListModel = customDemandListModel;
    
    self.topleftLab.text = customDemandListModel.category;
    self.botLeftLab.text = customDemandListModel.demand;
    self.topRightLab.text = [[[NSString stringWithFormat:@"倒计时：%@天",customDemandListModel.days] stringByAppendingString:[NSString stringWithFormat:@"%@小时",customDemandListModel.hours]] stringByAppendingString:[NSString stringWithFormat:@"%@分",customDemandListModel.mins]];
    self.botRightLab.text = [NSString stringWithFormat:@"竞标：%@",customDemandListModel.total];
}

- (void)setViewUI
{
    self.topleftLab = [[UILabel alloc] init];
    self.topleftLab.text = @"海报设计";
    self.topleftLab.textColor = FONTCOLOR_BLACK;
    self.topleftLab.font = Kfont(14);
    [self addSubview:self.topleftLab];
    
    [self.topleftLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(ScreenX375(15)));
        make.top.equalTo(@(ScreenX375(10)));
        make.height.equalTo(@(ScreenX375(15)));
        make.width.equalTo(@(ScreenX375(100)));
    }];
    
    self.topRightLab = [[UILabel alloc] init];
    self.topRightLab.right = 15;
    self.topRightLab.top = 10;
    self.topRightLab.size = CGSizeMake((SCREEN_WIDTH - ScreenX375(30))/2, (self.cellHeight - ScreenX375(20))/2);
    self.topRightLab.text = @"倒计时：30天22小时15分";
    self.topRightLab.textAlignment = NSTextAlignmentRight;
    self.topRightLab.textColor = RGB_COLOR(237,34,59);
    self.topRightLab.font = Kfont(12);
    [self addSubview:self.topRightLab];
    
    [self.topRightLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self).offset(-ScreenX375(15));
        make.top.equalTo(@(ScreenX375(12)));
        make.height.equalTo(@(ScreenX375(13)));
        make.width.equalTo(@(ScreenX375(150)));
    }];
    
    self.botLeftLab = [[UILabel alloc] init];
    self.botLeftLab.text = @"我需要包装设计  要求：根据包装出一份设计";
    self.botLeftLab.textColor = RGB_COLOR(153,153,153);
    self.botLeftLab.font = Kfont(12);
    [self addSubview:self.botLeftLab];
    [self.botLeftLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(ScreenX375(15)));
        make.bottom.equalTo(self).offset(-ScreenX375(10));
        make.height.equalTo(@(ScreenX375(15)));
        make.width.equalTo(@(ScreenX375(250)));
    }];
    
    self.botRightLab = [[UILabel alloc] init];
    self.botRightLab.text = @"竞标：8";
    self.botRightLab.textColor = RGB_COLOR(153,153,153);
    self.botRightLab.font = Kfont(12);
    [self addSubview:self.botRightLab];
    
    [self.botRightLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self).offset(-(ScreenX375(15)));
        make.bottom.equalTo(self).offset(-(ScreenX375(10)));
        make.height.equalTo(@(ScreenX375(13)));
        make.width.equalTo(@(ScreenX375(50)));
    }];
    
    UIImageView *lineImage = [[UIImageView alloc] init];
    lineImage.frame = CGRectMake(ScreenX375(15), self.botRightLab.bottom, SCREEN_WIDTH - ScreenX375(30), 1);
    lineImage.image = [UIImage imageNamed:@"虚线"];
//    [self addSubview:lineImage];
   
}

@end


#pragma mark - DesignCenterBtnTableViewCell
@interface DesignCenterBtnTableViewCell()

@property (nonatomic, assign) CGFloat  cellHeight;
@property (nonatomic, strong) NSIndexPath * indexPath;

@end

#pragma mark - 第0区的cell样式
@implementation DesignCenterBtnTableViewCell

+ (DesignCenterBtnTableViewCell *)cellBtnWithTableView:(UITableView *)tableView andIndexPath:(NSIndexPath *)indexPath andCellHeight:(CGFloat)height
{
    static NSString *cellID = @"DesignCenterBtnTableViewCell";
    DesignCenterBtnTableViewCell *cell = [[DesignCenterBtnTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    cell.indexPath = indexPath;
    cell.cellHeight = height;
    
    [cell setBtnViewUI];
    
    return cell;
}

-(void)waterClicked
{
    if (_waterClick) {
        _waterClick();
    }
}

-(void)colorClicked
{
    if (_colorClick) {
        _colorClick();
    }
}

-(void)digitalClicked
{
    if (_digitalClick) {
        _digitalClick();
    }
}

-(void)structClicked
{
    if (_structClick) {
        _structClick();
    }
}

- (void)setBtnViewUI
{
    CGFloat mar = (SCREEN_WIDTH - (self.cellHeight - 10)*4)/5;
    CGFloat marHei = self.cellHeight - 10;
    
    FPCustomButton * oneBtn = [FPCustomButton buttonWithType:UIButtonTypeCustom];
    [self addSubview:oneBtn];
    [oneBtn setImage:[UIImage imageNamed:@"彩印设计"] forState:UIControlStateNormal];
    [oneBtn setTitle:@"彩印设计" forState:UIControlStateNormal];
    [oneBtn setTitleColor:FONTCOLOR_BLACK forState:UIControlStateNormal];
    [oneBtn addTarget:self action:@selector(colorClicked) forControlEvents:UIControlEventTouchUpInside];
    oneBtn.titleLabel.font = Ffont(13);
    [oneBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(mar));
        make.top.equalTo(@10);
        make.width.height.equalTo(@(marHei));
    }];
    
    
    FPCustomButton * twoBtn = [FPCustomButton buttonWithType:UIButtonTypeCustom];
    [self addSubview:twoBtn];
    [twoBtn setImage:[UIImage imageNamed:@"水印设计"] forState:UIControlStateNormal];
    [twoBtn setTitle:@"水印设计" forState:UIControlStateNormal];
    [twoBtn setTitleColor:FONTCOLOR_BLACK forState:UIControlStateNormal];
    [twoBtn addTarget:self action:@selector(waterClicked) forControlEvents:UIControlEventTouchUpInside];
    twoBtn.titleLabel.font = Ffont(13);
    [twoBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(oneBtn.mas_right).offset(mar);
        make.top.equalTo(@10);
        make.width.height.equalTo(@(marHei));
    }];
    
    FPCustomButton * threeBtn = [FPCustomButton buttonWithType:UIButtonTypeCustom];
    [self addSubview:threeBtn];
    [threeBtn setImage:[UIImage imageNamed:@"数码设计"] forState:UIControlStateNormal];
    [threeBtn setTitle:@"数码设计" forState:UIControlStateNormal];
    [threeBtn setTitleColor:FONTCOLOR_BLACK forState:UIControlStateNormal];
    [threeBtn addTarget:self action:@selector(digitalClicked) forControlEvents:UIControlEventTouchUpInside];
    threeBtn.titleLabel.font = Ffont(13);
    [threeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(twoBtn.mas_right).offset(mar);
        make.top.equalTo(@10);
        make.width.height.equalTo(@(marHei));
    }];
    
    FPCustomButton * fourBtn = [FPCustomButton buttonWithType:UIButtonTypeCustom];
    [self addSubview:fourBtn];
    [fourBtn setImage:[UIImage imageNamed:@"结构设计"] forState:UIControlStateNormal];
    [fourBtn setTitle:@"结构设计" forState:UIControlStateNormal];
    [fourBtn setTitleColor:FONTCOLOR_BLACK forState:UIControlStateNormal];
    fourBtn.titleLabel.font = Ffont(13);
    [fourBtn addTarget:self action:@selector(structClicked) forControlEvents:UIControlEventTouchUpInside];
    [fourBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(threeBtn.mas_right).offset(mar);
        make.top.equalTo(@10);
        make.width.height.equalTo(@(marHei));
    }];
}

@end

#pragma mark - DesignCenterCarouselTableViewCell
@interface DesignCenterCarouselTableViewCell()<CHCardViewDelegate, CHCardViewDataSource>
///<NewPagedFlowViewDelegate, NewPagedFlowViewDataSource>

@property (nonatomic, assign) CGFloat             cellHeight;
@property (nonatomic, strong) NSIndexPath       * indexPath;
@property (nonatomic, strong) CHCardView        * cardView;

@end

#pragma mark - 第四区的cell样式
@implementation DesignCenterCarouselTableViewCell
+ (DesignCenterCarouselTableViewCell *)cellWithTableView:(UITableView *)tableView andIndexPath:(NSIndexPath *)indexPath andCellHeight:(CGFloat)height
{
    static NSString *cellID = @"DesignCenterCarouselTableViewCell";
    DesignCenterCarouselTableViewCell *cell = [[DesignCenterCarouselTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    cell.indexPath = indexPath;
    cell.cellHeight = height;
    
    [cell setCarouselViewUI];
    
    return cell;
}

-(void)setDesignCenterCardModel:(DesignCenterCardModel *)designCenterCardModel
{
    _designCenterCardModel = designCenterCardModel;
    
    
}

- (void)setCarouselViewUI
{
//    NewPagedFlowView *pageFlowView = [[NewPagedFlowView alloc] initWithFrame:CGRectMake(0, 10, SCREEN_WIDTH, self.cellHeight - 20)];
//    pageFlowView.delegate = self;
//    pageFlowView.dataSource = self;
//    pageFlowView.minimumPageAlpha = 0.1;
//    pageFlowView.isCarousel = YES;
//    pageFlowView.orientation = NewPagedFlowViewOrientationHorizontal;
//    pageFlowView.isOpenAutoScroll = NO;
//    [pageFlowView reloadData];
    
//    [self addSubview:pageFlowView];
    
    _cardView = [[CHCardView alloc] initWithFrame:CGRectMake(ScreenX375(13), 10, SCREEN_WIDTH - ScreenX375(26), ScreenX375((self.cellHeight - 40)))];
    _cardView.backgroundColor = [UIColor redColor];
    _cardView.delegate = self;
    _cardView.dataSource = self;
    [self addSubview:_cardView];
}

#pragma mark - CHCardViewDelegate
- (NSInteger)numberOfItemViewsInCardView:(CHCardView *)cardView {
    return self.valueArray.count;
}

- (CHCardItemView *)cardView:(CHCardView *)cardView itemViewAtIndex:(NSInteger)index {
    CHCardItemCustomView *itemView = [[CHCardItemCustomView alloc] initWithFrame:cardView.bounds];
    itemView.designCenterCardModel = self.valueArray[index];
    return itemView;
}

- (void)cardViewCurrentPage:(NSInteger)index {
    NSLog(@"%li",index);
}

- (void)cardViewNeedMoreData:(CHCardView *)cardView {
    // reload
    [self.cardView reloadData];
}

// select
- (void)cardView:(CHCardView *)cardView didClickItemAtIndex:(NSInteger)index {
    NSLog(@"%li",index);
}

/*
#pragma mark NewPagedFlowView Delegate
- (CGSize)sizeForPageInFlowView:(NewPagedFlowView *)flowView {
    
    return CGSizeMake(SCREEN_WIDTH - 60, self.cellHeight - 20);
}

- (void)didSelectCell:(UIView *)subView withSubViewIndex:(NSInteger)subIndex {
    
    NSLog(@"点击了第%ld张图",(long)subIndex + 1);
    
    //    self.indicateLabel.text = [NSString stringWithFormat:@"点击了第%ld张图",(long)subIndex + 1];
}

- (void)didScrollToPage:(NSInteger)pageNumber inFlowView:(NewPagedFlowView *)flowView {
    
    NSLog(@"ViewController 滚动到了第%ld页",(long)pageNumber);
}

#pragma mark NewPagedFlowView Datasource
- (NSInteger)numberOfPagesInFlowView:(NewPagedFlowView *)flowView {
    
    return 5;
    
}

- (PGIndexBannerSubiew *)flowView:(NewPagedFlowView *)flowView cellForPageAtIndex:(NSInteger)index{
    PGIndexBannerSubiew *bannerView = [flowView dequeueReusableCell];
    if (!bannerView) {
        bannerView = [[PGIndexBannerSubiew alloc] init];
        bannerView.tag = index;
        bannerView.layer.cornerRadius = 4;
        bannerView.layer.masksToBounds = YES;
    }
    //在这里下载网络图片
    //  [bannerView.mainImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:hostUrlsImg,imageDict[@"img"]]] placeholderImage:[UIImage imageNamed:@""]];
    bannerView.mainImageView.image = [UIImage imageNamed:@"背景2.png"];
    
    bannerView.backgroundColor = [UIColor grayColor];
    
    return bannerView;
}
 */

@end




